<template>
  <el-container style="min-height: 100vh;">
    <!-- 侧边栏 -->
    <el-aside width="sideWidth + 'px'"
      style="background-color: rgb(238, 241, 246); box-shadow: 2px 0 6px rgba(0,21,41,0.35)">
      <Aside :isCollapse="isCollapse" :logoTextShow="logoTextShow"/>
    </el-aside>

    <el-container>
      <!-- 头部 -->
      <el-header style="border-bottom: 1px solid #ccc;">
        <Header :collapseBtnClass="collapseBtnClass" :collapse="collapse" :pathName="pathName" :user="user"/>
      </el-header>
      <!-- 主体 -->
      <el-main>
        <!-- router-view子路由展示 -->
        <router-view @refreshUser="getUser" />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  // import request from "@/utils/request"
  import Aside from "@/components/Aside"
  import Header from "@/components/Header"
  export default {
    name: 'Home',
    data() {
      return {
        collapseBtnClass: 'el-icon-s-fold',
        isCollapse: false,
        sideWidth: 200,
        logoTextShow: true,
        user: {},
      }
    },
    components: {
      Aside,
      Header,
    },
    created() {
      this.getUser()
    },
    methods: {
      // 收缩按钮触发
      collapse() {
        this.isCollapse = !this.isCollapse
        if (this.isCollapse) {
          this.sideWidth = 64
          this.collapseBtnClass = 'el-icon-s-unfold'
          this.logoTextShow = false
        } else {
          this.sideWidth = 200
          this.collapseBtnClass = 'el-icon-s-fold'
          this.logoTextShow = true
        }
      },
      getUser() {
        let username = localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")).username : ""
        this.request.get("/user/username/" + username).then(res => {
          this.user = res.data 
        })
      },
    }
  }
</script>

<style scoped>

</style>